import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

/**
 * AdapterPattern
 */
public class AdapterPattern {
    public static void main(String[] args) {
        var other = new Other() {};
        var adapter = new AnotherAdapter(other, new Another() {});
        Logger.getGlobal().info(String.format("excpect:%d adapter:%d",
                other.add(1, 2), adapter.add(1, 2)));
    }
}

interface Other {
    default Integer add(Integer a, Integer b) {
        return a + b;
    }
}

interface Another {
    default void add(Map<String, Integer> m) {
        var a = (m.get("a") == null ? 0 : m.get("a"));
        var b = (m.get("b") == null ? 0 : m.get("b"));
        m.put("c", a + b);
    }
}

class AnotherAdapter implements Other {
    Other other;
    Another another;

    public AnotherAdapter(Other other, Another another) {
        this.other = other;
        this.another = another;
    }

    @Override
    public Integer add(Integer a, Integer b) {
        var m = new HashMap<String, Integer>() {{
            put("a", a);
            put("b", b);
        }};
        another.add(m);
        return (m.get("c") == null ? 0 : m.get("c"));
    }
}